﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;

namespace AiSk.Impl
{
    public class OpenAiService : BaseLLmService
    {
        public override async Task Embeddings()
        {
            throw new NotImplementedException();
        }

        public override async Task Chat(string question, string system, string model = "gpt-35-turbo")
        {
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Authorization", $"Bearer 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");
                var requestBody = new
                {
                    model = "gpt-35-turbo",
                    messages = new object[] {
        new {role="system",content= question},
        new {role= "user",content= "Hello!"}}
                };

                var response = await client.PostAsJsonAsync("https://api.openai.com/v1/chat/completions", requestBody);

                if (response.IsSuccessStatusCode)
                {
                    var result = await response.Content.ReadAsStringAsync();
                    Console.WriteLine(result);
                }
                else
                {
                    Console.WriteLine("Error occurred: " + response.ReasonPhrase);
                }
            }
        }
    }
}
